<!DOCTYPE HTML>
<html style="background: #f9f9f9">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>法援宝</title>
    <link rel="stylesheet" type="text/css" href="../css/api.css" />
    <link rel="stylesheet" type="text/css" href="../css/style.css" />
    <link rel="stylesheet" type="text/css" href="../css/lawyer_user.css" />
    <script type="text/javascript" src="../script/api.js"></script>
    <script type="text/javascript" src="../script/jquery-1.9.1.min.js"></script>
    <script type="text/javascript" src="../script/mobile.js"></script>
    <script type="text/javascript" src="../script/lawyer.js"></script>

    <script type="text/javascript" src="../script/mobile-detect.js"></script>
    <script type="text/javascript" src="../script/mobile-detect.min.js"></script>
    <style type="text/css">
    .remember{
        display: flex;
        align-items: center;
        height: 0.4rem;
        font-size: 0.26rem;
        color: #666666;
        padding-left: 0.2rem;
        justify-content: space-between;
    }
    .reBtn{
        display: inline-block;
    }
    .reBtn input{
        position: relative;
        top: 0.03rem;
        margin-right: 0.05rem;
    }
    </style>
</head>
<body style="background: #f9f9f9">
<div id="secHeader">
  <header class="header">
      <!--<a href="javascript:void(0);"  class="back_btn"><img src="../image/head-fanhui.png" alt=""></a>-->
      <h2>登录</h2>
      <a href="javascript:void(0);" class="qiandao_btn"  onclick="aaplay('register')"  style="position: absolute;  right: 3%; top: 0; color: #fff;">注册</a>
  </header>
</div>
<section class="login_choose">
    <ul>
        <li class="active"><a href="javascript:;">账号密码登录</a></li>
        <li><a href="javascript:;" onclick="aaplay('login_account')">手机快捷登录</a></li>
    </ul>
</section>

<section class="login_section">
    <div class="fyb_logo"><img src="../image/fyb_logo.png" alt=""></div>
    <div class="login_box">
        <ul>
            <li class="username"><input type="text" placeholder="请输入手机号/账号" id='phone'></li>
            <li class="tel_code"><input type="password" placeholder="请输入密码" id='password'></li>
        </ul>
         <div class="remember">
            <div class="reBtn" style='cursor: pointer'><input class="reChecked" type="checkbox" checked="checked">记住密码</div>
            <div onclick="forgetPlay()">忘记密码？</div>
        </div>

        <p class="agree">成功登录即表示您同意<a href="##" onclick="aaplay('yhxy')">《用户协议》</a></p>
        <button class="login_submit" type="submit" onclick="login()">进入法援宝</button>
    </div>
    <div class="login_kinds" style="">
        <h6><span>第三方登录</span></h6>
        <ul>
            <li class="qq"><a href="javascript:;" onclick="sanfang_qq()"><img src="../image/ologin1.png" alt=""></a></li>
            <li class="wx"><a href="javascript:;" onclick="initWXBind()"><img src="../image/ologin2.png" alt=""></a></li>
            <li class="wb"><a href="javascript:;" onclick="initWBBind()"><img src="../image/ologin3.png" alt=""></a></li>
        </ul>
    </div>
</section>
<aside class="download">
    <a href="##" class="user_download">普通用户点击下载【法援宝】</a>
</aside>


</body>

<script>
    var mt
    apiready = function () {
      $api.fixStatusBar( $api.dom('#secHeader') );
      api.setStatusBarStyle({
          style: 'light'
      });


        $('#phone').val($api.getStorage ('phone'));
        if($api.getStorage ('password') != null){
            $('#password').val($api.getStorage ('password'))
        }

        var md = new MobileDetect(
            'Mozilla/5.0 (Linux; U; Android 4.0.3; en-in; SonyEricssonMT11i' +
            ' Build/4.1.A.0.562) AppleWebKit/534.30 (KHTML, like Gecko)' +
            ' Version/4.0 Mobile Safari/534.30');

       var os = md.os();//获取系统  
       if (os == "iOS") {//ios系统的处理  
           mt=2
       }else if(os == "AndroidOS") {//Android系统的处理  
           mt=1
       }

        //apk()

        // ios 登录检测是否安装第三方app
         check_qq();
         check_wx();
         check_wb();

    }

    

    $(".reBtn").click(function () {
        if($(".reChecked").prop('checked')){
            $(this).find('input[type=checkbox]').prop('checked',false);
        }else {
            $(this).find('input[type=checkbox]').prop('checked',true);
        }
    });
    function apk(){
        if(mt==1){
            var p={id:31};
        }else {
           var p={id:32};
        }

        api.ajax({
            url: webSiteUrl+'/app/public/ad',
            method: 'post',
            data: {

                values: p
            }
        }, function(ret, err) {


            if(ret.code==200){

                var tj=ret.data;
                if(tj != null){
                    $('.user_download').attr('href',webSiteUrl+tj.file);
                    $('.user_download').attr('download',webSiteUrl+tj.file);

                }
            }

        });

    }
    function login(){
        var phone=$("#phone").val();
        var password=$("#password").val();

        if(phone==''){
            alert("请输入手机号！");return;
        }else if(!/^1[345678]\d{9}$/.test(phone)){
            alert("手机号格式错误！");return;
        }else if(password==''){
            alert("请输入密码！");return;
        }else if(!/^(\w){6,20}$/.test(password)){
            alert("密码必须是6-20个字母、数字、下划线！");return;
        }

        var p={phone:phone,password:password,type:2};
        api.ajax({
            url: webSiteUrl+'/app/public/login',
            method: 'post',
            data: {

                values: p
            }
        }, function(ret, err) {



            if(ret.code==200){
                alert(ret.msg)
                //alert(JSON.stringify(ret.data));
                $api.clearStorage();
                $api.setStorage('user',ret.data);
                $api.setStorage('phone',phone);
                if($(".reChecked").prop('checked')){
                    $api.setStorage('password',password);
                }

                aaplay('workbench')

            }else{alert(ret.msg)}
        });

    }


     //qq登录
       function sanfang_qq(){
            var qq = api.require('qq');
            var openId = '';
            qq.installed(function(ret, err) {
                if (!ret.status) {
                    api.alert({ msg: "当前设备未安装QQ客户端" });
                } else {
                    qq.login(function(ret, err) {
                        if (ret.status) {
                            openId = ret.openId;
                            qq.getUserInfo(function(ret, err) {
                                if (ret.status) {
                                    //alert(JSON.stringify(ret.info));
                                    QQbindAccount(openId,ret.info.nickname,ret.info.figureurl_qq_1);
                                } else {
                                    api.alert({ msg: err.msg });
                                }
                            });
                        }
                    });
                }
            });
        }



        //qq登录传值
        function QQbindAccount(openid,nickname,imgurl){

          var dd = {openid:openid, type:2};
          var d = {openid:openid,type:2,'username':nickname,icon:imgurl};
          api.ajax({
              url: webSiteUrl+'/app/public/checkOpenid',
              method: 'post',
              data: {
                  values: dd
              }
          },function(ret, err){
              if (ret.code==200) {

                api.ajax({
                    url: webSiteUrl+'/App/public/three',
                    method: 'post',
                    data: {
                        values: d
                    }
                }, function(ret, err) {
                    if (ret.code == 200) {

                        $api.clearStorage();
                        $api.setStorage("user",ret.data);
                        aaplay('workbench')

                    }else{
                        alert(ret.msg);
                        //alert('222')
                    }
                });


              } else {

                api.openWin({
                    name: 'loginbang',
                    url: './loginbang.html',
                    reload:true,
                    pageParam: {
                        data: d
                    }
                });


              }
          });
        }



         //微信登录22222222222222222222222222222
          function initWXBind() {
            // alert('该功能暂未实现');
            // return;
            var wx = api.require('wx');
            var code = '';
            wx.isInstalled(function(ret, err) {
                if (!ret.installed) {
                    alert("当前设备未安装微信客户端");
                } else {
                    wx.auth({
                        apiKey: 'wx00ebcf3ca5271e58'
                    }, function(ret, err) {
                        if (ret.status) {
                          //  alert(JSON.stringify('code:'+ret.code));

                            wx.getToken({
                                code: ret.code
                            }, function(ret, err) {
                            //    alert(JSON.stringify(ret));
                                if (ret.status) {
                                     api.showProgress({
                                        style: 'default',
                                        animationType: 'fade',
                                        title: '授权成功',
                                        text: '绑定处理中...',
                                        modal: true
                                    });
                                    wx.getUserInfo({
                                        accessToken: ret.accessToken,
                                        openId: ret.openId
                                    }, function(ret, err) {
                                      //  alert("获取用户信息");
                                      //  alert(JSON.stringify(ret));
                                        if (ret.status) {
                                            // 绑定成功
                                            WXbindAccount(ret.openid,ret.nickname,ret.headimgurl);
                                            api.hideProgress();
                                        }
                                    });
                                } else {
                                    alert(err.code+','+err.msg);
                                }
                            });
                        }else{

                        }
                    });
                }
            });
        }



          function WXbindAccount(openid,nickname,imgurl) {
            var dd = {openid:openid, type:2};
            var d = {openid:openid,type:2,'username':nickname,icon:imgurl};
            api.ajax({
                url: webSiteUrl+'/app/public/checkOpenid',
                method: 'post',
                data: {
                    values: dd
                }
            },function(ret, err){
                if (ret.code==200) {

                  api.ajax({
                      url: webSiteUrl+'/App/public/three',
                      method: 'post',
                      data: {
                          values: d
                      }
                  }, function(ret, err) {
                      if (ret.code == 200) {

                          $api.clearStorage();
                          $api.setStorage("user",ret.data);
                          aaplay('workbench')

                      }else{
                          alert(ret.msg);
                          //alert('222')
                      }
                  });


                } else {

                  api.openWin({
                      name: 'loginbang',
                      url: './loginbang.html',
                      reload:true,
                      pageParam: {
                          data: d
                      }
                  });


                }
            });
        }




        //微博登录
         function initWBBind() {
            var weibo = api.require('weibo');
            weibo.isInstalled(function(ret) {
                if (!ret.status) {
                    alert('未安装新浪微博客户端');
                } else {
                    weibo.auth(function(ret, err) {
                        if (ret.status) {
                            weibo.getUserInfo({
                                token: ret.token,
                                userId: ret.userId
                            }, function(ret, err) {
                                if (ret.status) {
                                    //alert(JSON.stringify(ret.userInfo))
                                    WBbindAccount(ret.userInfo.id,ret.userInfo.screen_name,ret.userInfo.profile_image_url);
                                }
                            });
                        }
                    });
                }
            });
        }

        //微博传值
        function WBbindAccount(openid,nickname,imgurl) {
          var dd = {openid:openid, type:2};
          var d = {openid:openid,type:2,'username':nickname,icon:imgurl};
          api.ajax({
              url: webSiteUrl+'/app/public/checkOpenid',
              method: 'post',
              data: {
                  values: dd
              }
          },function(ret, err){
              if (ret.code==200) {

                api.ajax({
                    url: webSiteUrl+'/App/public/three',
                    method: 'post',
                    data: {
                        values: d
                    }
                }, function(ret, err) {
                    if (ret.code == 200) {

                        $api.clearStorage();
                        $api.setStorage("user",ret.data);
                        aaplay('workbench')

                    }else{
                        alert(ret.msg);
                        //alert('222')
                    }
                });


              } else {

                api.openWin({
                    name: 'loginbang',
                    url: './loginbang.html',
                    reload:true,
                    pageParam: {
                        data: d
                    }
                });


              }
          });

        }


</script>
</html>
